package com.example.leetcode;


import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class RemoveElement {

    @Test
    public void testRemoveElement() {
        int[] nums = new int[]{3, 2, 2, 3};
        int i = removeElement(nums, 2);
        System.out.println(i);
    }

    public int removeElement(int[] nums, int val) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[index++] = nums[i];
            }
        }
        System.out.println(Arrays.toString(nums));
        return index;
    }
}
